//
//  LDMyResumeCellExpRowInAll.swift
//  DingDongZP
//
//  Created by ZZN on 16/12/29.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

import UIKit

class LDMyResumeCellExperienceInAll_Row: UIView {
    
    
    static let textViewWidth:CGFloat = LDMyResumeCellMyAdvantageInAll_Row.textViewWidth
    var companyName:UILabel?
    var jobName:UILabel?
    var jobTag:UILabel?//标签
    var jobDescLab:UILabel?
    
    var timeLab:UILabel?
    
    let SameLabTag = 333
    
    var dotView:UIImageView?
    var divideLine:UIView?
    
    var model:DDMyResumeWorkexperience? = nil {
        
        didSet{
            
            updateFrame()
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setDefaultContent()
    }
    
    func updateFrame() {
        

        jobDescLab?.attributedText =  String.getAttrFormString(lineH: LDFrame.AttrLineH, text: model?.jobdesc ?? "", font: LDFont.Font14)
        companyName?.text = "\(model!.companyname) | \(model!.industryname)"
        jobName?.text = "\(model!.jobtitle) | \(model!.department)"
        timeLab?.text = "\(model!.startdate) - \(model!.enddate)"
        
        let tagList = model!.jobstrenths.map { (obj) -> String in
            
            return obj.tag ?? ""
        }
        
        if tagList.count == 0 {
            return
        }
        
        let offY:CGFloat = 60
        UILabel.creatLabsFromArrTags(tagList, labsTag: self.SameLabTag, labH: 20, font: LDFont.Font13, toView: self, originX: 23, originY: offY, marginX: 13, marginY: 13)
//        let attrTagH = UILabel.getLabsAllHight(tagList, labH: 20, font: LDFont.Font13, originX: 23, marginX: 13, marginY: 13)
        
        
        let labLast = self.viewWithTag(tagList.count+self.SameLabTag-1) as! UILabel
        self.jobDescLab?.snp_makeConstraints(closure: { (make) in
            
            make.top.equalTo(labLast.snp_bottom).offset(LDMargin_V*2)
            make.height.equalTo(self.getAttrHeight())
            make.left.equalTo(LDMargin_V*5)
            make.right.equalTo(-LDMargin_V)
        })
    }
    
    //工作详情高度
    func getAttrHeight() ->CGFloat{
        
        let attrH = String.getHeightFormAttr(LDFrame.AttrLineH, title: model!.jobdesc ?? "", size: CGSizeMake(LDMyResumeCellExperienceInAll_Row.textViewWidth,1000), font: LDFont.Font14)
        
        //getAttrFormString(lineH: LDFrame.AttrLineH, text: model.jobdesc ?? "", font: LDFont.Font14)
        return attrH
    }
    
    //标签高度
    func getLabsTagHeight() -> CGFloat {
        
        let tagList = model!.jobstrenths.map { (obj) -> String in
            
            return obj.tag ?? ""
        }
        let attrTagH = UILabel.getLabsAllHight(tagList, labH: 20, font: LDFont.Font13, originX: 23, marginX: 13, marginY: 13)
        
        return attrTagH

    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setDefaultContent() {
        
        self.frame = LDFrame.ScreenBounds
        
        companyName = UILabel.setDetailsLab("互联网 | 杭州乐电网络科技有限公司", fontSize: 14, titleColor:LDFontColor.DeepGray,Alignment: .Left)
        timeLab = UILabel.setDetailsLab("2008 - 2015", fontSize: 14, titleColor:LDFontColor.DeepGray,Alignment: .Left)
        jobName = UILabel.setDetailsLab("设计师 | 视觉设计", fontSize: 14, titleColor:LDFontColor.DeepGray,Alignment: nil)
        jobDescLab = UILabel.setDetailsLab("", fontSize: 13, titleColor: LDFontColor.LightGray,Alignment: nil)
        
        
        divideLine = UIView()
        divideLine?.backgroundColor = LDLineColorLightGray
        
        dotView = UIImageView(image: UIImage(named: "green_dot"))
        
        addSubview(dotView!)
        addSubview(divideLine!)
        addSubview(companyName!)
        addSubview(timeLab!)
        addSubview(jobName!)
        addSubview(jobDescLab!)
        
        
        dotView?.snp_makeConstraints(closure: { (make) in
            
            make.top.equalTo(0)//.offset(LDMargin_V*3)
            make.left.equalTo(0)
            make.size.equalTo(CGSizeMake(10, 10))
        })
        
        divideLine?.snp_makeConstraints(closure: { (make) in
            make.top.equalTo(dotView!.snp_bottom)
            make.centerX.equalTo(dotView!)
            make.bottom.equalTo(0)
            make.width.equalTo(0.5)
        })
        
        
        timeLab?.snp_makeConstraints(closure: { (make) in
            
            make.centerY.equalTo(dotView!)
            make.left.equalTo(dotView!.snp_right).offset(LDMargin_V*2)
            make.height.equalTo(20)
            make.right.equalTo(LDMargin_V)
            
        })
        
        companyName?.snp_makeConstraints(closure: { (make) in
            
            make.top.equalTo((timeLab?.snp_bottom)!).offset(LDMargin_V)
            make.left.height.right.equalTo(timeLab!)
        })
        
        jobName?.snp_makeConstraints(closure: { (make) in
            
            make.top.equalTo((companyName?.snp_bottom)!).offset(LDMargin_V)
            make.left.height.right.equalTo(timeLab!)
        })
    }
    

    
    
}
